# !/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2021/10/27 9:49
# @Author  : zuodengbo
# @Email   : zuodb@amoydx.com
# @File    : func_time
# @Software: PyCharm
import time


def timer(func):
    """
    计时器：函数耗时装饰器
    :param func:
    :return:
    """
    def wrapper(*args, **kwargs):
        name = func
        for attr in ("__qualname__", "__name__"):
            if hasattr(func, attr):
                name = getattr(func, attr)
                break

        print("Start call: {}".format(name))
        now = time.time()
        result = func(*args, **kwargs)
        using = (time.time() - now)
        msg = "End call {}, using: {:.3f}s".format(name, using)
        print(msg)
        return result
    return wrapper
